$(function () {

    var form = new xhForm($('#xh_form'));
    form.parse();

    if(carInfo!=1){
        form.fill(carInfo);
        $('[name=mDesc]').val('');
        if(flag == 1){
            if(carInfo['tRealStart']!=null){
                $('[name=time]').val(carInfo['tRealStart']);
            }
        }else {
            if(carInfo['tRealEnd']!=null){
                $('[name=time]').val(carInfo['tRealEnd']);
            }
        }
    }

    $('.form-date').datetimepicker({format: 'yyyy-mm-dd hh:ii',language: 'zh-CN',minView: "hour", autoclose:true});

    form.bindRequired($('#bt_modal_confirm',parent.document));

    $('#bt_modal_confirm',parent.document).click(function () {
        if(flag == 1){
            $.ajax({
                url:baseUrl+'lm/car/saveConfirm',
                data:$('#xh_form').serialize(),
                type:'POST',
                success:function (data) {
                    $('#bt_modal_confirm',parent.document).addClass('disabled');
                    $('#bt_modal_top_close',window.parent.document).click();
                    window.parent.useCarList.dataGridReload();
                },
                error:function (data) {
                    window.top.swal(
                        data['responseText'],
                        '',
                        'error'
                    );
                }
            });
        }else {
            $.ajax({
                url:baseUrl+'lm/car/saveConfirm/true',
                data:$('#xh_form').serialize(),
                type:'POST',
                success:function (data) {
                    $('#bt_modal_top_close',window.parent.document).click();
                    window.parent.useCarList.dataGridReload();
                },
                error:function (data) {
                    window.top.swal(
                        data['responseText'],
                        '',
                        'error'
                    );
                }
            });
        }
    });


});